package kr.pe.johnkim.chattingday.mobile.rest.dao;

import kr.pe.johnkim.chattingday.mobile.domain.ChattingDayGatheringMessageWarning;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

/**
 * Chatting Day 채팅방 메시지 신고/처리를 위한 DAO 메소드들을 구현한 클래스 이다.
 *
 * @author : johnkim <cale9797@gmail.com / Bettersoft Inc,.>
 * @Date : 12. 6. 7
 */
public class ChattingDayGatheringMessageWarningDaoImpl extends SqlMapClientDaoSupport implements ChattingDayGatheringMessageWarningDao {

    // SLF4J Logging
	private Logger logger = LoggerFactory.getLogger(ChattingDayGatheringMessageWarningDaoImpl.class);

    /**
     * 채팅방 불량 메시지에 경고를 추가 한다.
     *
     * @return
     */
    @Override
    public boolean registerGatheringWarning(ChattingDayGatheringMessageWarning chattingDayGatheringMessageWarning) {
        logger.info("registerGatheringWarning");

        boolean result;

        try {
            getSqlMapClientTemplate().insert("CHATTINGDAY_GATHERING_MESSAGE_WARNING.registerGatheringWarning", chattingDayGatheringMessageWarning);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 채팅방 불량 메시지에 경고 추가한 것을 취소 한다.
     *
     * @param chattingDayGatheringMessageWarning
     *
     * @return
     */
    @Override
    public boolean updateDeactivateGatheringMessageWarning(ChattingDayGatheringMessageWarning chattingDayGatheringMessageWarning) {
        logger.info("updateDeactivateGatheringMessageWarning");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_GATHERING_MESSAGE_WARNING.updateDeactivateGatheringMessageWarning", chattingDayGatheringMessageWarning);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 채팅방 해당 불량 메시지의 신고 총 건수를 가져 온다.
     *
     * @param chattingDayGatheringMessageWarning
     *
     * @return
     */
    @Override
    public ChattingDayGatheringMessageWarning selectGatheringMessageWarningCount(ChattingDayGatheringMessageWarning chattingDayGatheringMessageWarning) {
        logger.info("selectGatheringMessageWarningCount");

        return (ChattingDayGatheringMessageWarning)getSqlMapClientTemplate().queryForObject("CHATTINGDAY_GATHERING_MESSAGE_WARNING.selectGatheringMessageWarningCount", chattingDayGatheringMessageWarning);
    }
}
